<template>
  <div>
    <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        <a-col :span="6">
          <a-form-item label="网点名称">
          <a-input placeholder="请输入网点名称" v-model="queryParam.meshPointName"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="6">
          <a-form-item label="网点编号">
          <a-input placeholder="请输入网点编号" v-model="queryParam.meshPointCode"></a-input>
          </a-form-item>
        </a-col>
        <a-col :span="6">
          <a-form-item label="网点状态">
            <a-select   v-model="queryParam.meshPointsType" placeholder="请选择网点状态">
                  <a-select-option v-for="(item, index)  in meshPointsTypedata" :key="index.toString()" :value="item.id"> {{item.name}}</a-select-option>
          </a-select>
          </a-form-item>
        </a-col>
        <a-col :span="6" >
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{$t('common.query')}}</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">{{$t('common.reset')}}</a-button>
              
            </span>
          </a-col>
       </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">{{$t('common.table.add')}}</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('charge_mesh_point')">{{$t('common.table.export')}}</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">{{$t('common.table.import')}}</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
     <!-- <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      --> <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>{{$t('common.table.delete')}}</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px">{{$t('common.table.batchActions')}}<a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i>{{$t('common.table.selected')}}<a style="font-weight: 600">{{ selectedRowKeys.length }}</a>{{$t('common.table.item')}}
        <a style="margin-left: 24px" @click="onClearSelected">{{$t('common.table.empty')}}</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">{{$t('common.table.edit')}}</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">{{$t('common.table.more')}} <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">{{$t('common.table.detail')}}</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定设置维护状态?" @confirm="() => handledata(record.id)">
                  <a>维护</a>
                </a-popconfirm>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm :title="$t('common.table.confirmDelete')" @confirm="() => handleDelete(record.id)">
                  <a>{{$t('common.table.delete')}}</a>
                </a-popconfirm>
              </a-menu-item>
              <!-- <a-menu-item>
                <a @click="handleto(record.id)">柜子</a>
              </a-menu-item>
              <a-menu-item>
                <a @click="handletos(record.id)">电池</a>
              </a-menu-item> -->
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>
    
    
    <rental-store-modal ref="modalForm" @ok="modalFormOk"></rental-store-modal>
  </a-card>
  

  </div>
  
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import RentalStoreModal from './modules/RentalStoreModal'
  import { httpAction, getAction } from '@/api/manage'
  import TencentMap from "@comp/map/TencentMap";
  export default {
    name: 'RentalStoreList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      RentalStoreModal,TencentMap
    },
    data () {
      return {
        description: 'charge_mesh_point管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'网点分类',
            align:"center",
            dataIndex: 'storeCategory',
            customRender:(text)=> {
              console.log("storeCategoryDict", this.storeCategoryDict);
              if(text && this.storeCategoryDict.length > 0){
                console.log("storeCategoryDict", this.storeCategoryDict);
                const type = this.storeCategoryDict.find(a=> a.value == text);
                return type.label;
              }
              return text;
            }
          },
          {
            title:'网点编码',
            align:"center",
            dataIndex: 'meshPointsCode'
          },
          {
            title:'网点名称',
            align:"center",
            dataIndex: 'meshPointsName'
          },
          // {
          //   title:'运营区域',
          //   align:"center",
          //   dataIndex: 'regionName'
          // },
          {
            title:'邮政编码',
            align:"center",
            dataIndex: 'zipCode'
          },
          {
            title:'网点状态',
            align:"center",
            dataIndex: 'meshPointsType',
             customRender:function (text) {
              if(text==1){
                return '启用'
              }else if(text==2){
                return '维护'
              }else{
                return '删除'
              }
            }
            
          },
          {
            title:'网点图片',
            align:"center",
            dataIndex: 'pic',
             scopedSlots: { customRender: 'imgSlot' }
          },
          {
            title:'详细地址',
            align:"center",
            dataIndex: 'detailedAddress'
          },
          {
            title: this.$t('common.table.actions'),
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/rental/store/list",
          delete: "/rental/store/delete",
          deleteBatch: "/rental/store/deleteBatch",
          exportXlsUrl: "/rental/store/exportXls",
          importExcelUrl: "/rental/store/importExcel",
          edit:"/rental/store/edit",
          modify_state:"/rental/store/modify_state",
          store_category: "/rental/store-category/options"
        },
        meshPointsTypedata:[
          {name:'启用',id:1},
          {name:'维护',id:2},
          {name:'删除',id:3},
        ],
        queryParam:{},
        dictOptions:{},
        superFieldList:[],
        storeCategoryDict:[],
      }
    },
    created() {
      this.getSuperFieldList();
      this.getStoreCategoryDict();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'storeCategory',text:'网点分类'})
        fieldList.push({type:'string',value:'meshPointsCode',text:'网点编码'})
        fieldList.push({type:'string',value:'meshPointsName',text:'网点名称'})
        fieldList.push({type:'string',value:'personChargeId',text:'网点负责人id'})
        fieldList.push({type:'select',value:'meshPointsType',text:'网点状态',options: [
          {label: "启用",value: 1},
          {label: "维护",value: 2},
          {label: "删除",value: 3},
        ]})
        fieldList.push({type:'string',value:'provinceName',text:'省名称'})
        fieldList.push({type:'string',value:'cityName',text:'市名称'})
        fieldList.push({type:'string',value:'areaName',text:'区名称'})
        this.superFieldList = fieldList
      },
      handledata(e){
        console.log(94,e)
        let data={
           id:e,
           meshPointsType:2
        }
        httpAction(this.url.modify_state, data, 'post').then((res) => {
        if (res.success) {
          this.$message.success(res.message)
          this.close()
        } else {
          this.$message.warning(res.message)
        }
        }).finally((res) => {
          this.$message.warning(res.message)
          this.confirmLoading = false
        })
      },
      handleto(e){
        this.$router.push({
          name: 'chargecabinetlist-chargecabinetlist', // 去 demo1 文件夹下寻找 test 组件
          query: {  // 路由携带参数
            'id': e
          }
        });
      },
      handletos(e){
        this.$router.push({
          name: 'chargebatterylist-chargebatterylist', // 去 demo1 文件夹下寻找 test 组件
          query: {  // 路由携带参数
            'id': e
          }
        });
      },
      getStoreCategoryDict(){
        httpAction(this.url.store_category,{},'get').then((res)=>{
          this.storeCategoryDict=res.result;
          console.log("getStoreCategoryDict:", this.storeCategoryDict);
        }).finally(() => {

        })
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>